package week4.day26;

import java.lang.reflect.Field;

/**
 * @Author fengzihao
 * @Date 2024-05-10 20:04
 */
public class Work1 {

/**
 * @param targetObj 要修改成员变量值的目标对象
 * @param fieldName 对象中要修改的成员变量的名字
 * @param newValue 要修改成员变量值的新值
 * */
    public static void setAll(Object targetObj, String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
        Class aClass = targetObj.getClass();
        Field field = aClass.getField(fieldName);
        field.setAccessible(true);
        field.set(targetObj,newValue);
    }
}